import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import dayjs from 'dayjs';
import i18next from 'i18next';

// 定义 state 类型
interface MySettingState {

    softwareLanguage: string;
    myLanguage: string
}

const initialState: MySettingState = {
    softwareLanguage: '中文（简体）',
    myLanguage: '中文（简体）'

}

let MySettingSlice = createSlice({
    name: 'MySettingSlice',
    initialState,
    reducers: {


        setMyLanguage(state, action: PayloadAction<string>) {
            if (action.payload === '中文（简体）') {
                i18next.changeLanguage('zh')
            } else {
                i18next.changeLanguage('en')
            }
            state.myLanguage = action.payload
        },
        setSoftwareLanguage(state, action: PayloadAction<string>) {
            if (action.payload === '中文（简体）') {
                i18next.changeLanguage('zh')
            } else {
                i18next.changeLanguage('en')
            }
            state.softwareLanguage = action.payload
        }

    }
})

export default MySettingSlice

// 导出 action creator
export let { setMyLanguage, setSoftwareLanguage } = MySettingSlice.actions